<script>
import Son from './Son.vue'
import { mapState, mapGetters, mapMutations, mapActions } from 'vuex'
export default {
  components: { Son },
  name: 'Father',
  methods: {
    ...mapActions(['getData', 'jia']),
    ...mapMutations(['JIA']),
    handleClick() {
      this.$nextTick(() => {
        this.$refs.child.sonMethod()
      })
    },
    sendMsg() {
      $bus.$emit('send', '我是发过来的')
    },
    fatherMethod(sonData) {
        console.log('fathermethoiod>>>>>>>>>', sonData);
        sonData()
    },
    sonToFatherMethed(msg) {
      console.log(msg)
    },
    sonToFatherMethedEmit(emitMsg) {
      console.log(emitMsg)
    }
  },
  mounted() {
    console.log(111111111111, this.$store.state.test.sum);
    this.JIA(22)
    
    // this.$store.dispatch('getData', '111').then(res => {
    //   console.log(22222222,res);
    // })
    this.getData('1112').then(res=> {
      console.log(22222222,res);
    })
    this.jia(10)
  },
  data() {
    return {
      fatherKey: 11111,
    }
  },
  computed: {
    //借助mapState生成计算属性：sum、school、subject（数组写法）
    ...mapState({
      sum: state=> state.test.sum
    }),
    ...mapGetters(['bigSum'])
  },
}
</script>
<template>
  <div>
    <button @click="handleClick">++++++</button>
    <button @click="sendMsg">$emit>>>>></button>

    <Son  
      ref="child" 
      :father-msg="fatherKey" 
      :father-handle = 'fatherMethod' 
      :sonToFather="sonToFatherMethed"
      @sonToFatherEmit="sonToFatherMethedEmit"
    />
    <div>store: {{sum}}</div>
      <div>store: {{bigSum}}</div>
  </div>
</template>